{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "88c5b893-92ae-4084-bcda-56a05ee373bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1ffd3f97-bb2f-4c17-800f-bd5fc0b9f00c",
   "metadata": {},
   "outputs": [],
   "source": [
    "v0 = torch.tensor([np.sqrt(2), 0])\n",
    "v1 = torch.tensor([0.1,  1.7277152543170995])\n",
    "angle = (v0 * v1).sum(-1)\n",
    "\n",
    "cos_theta = angle / (np.sqrt((v0 * v0).sum(-1)) *\n",
    "                     np.sqrt((v1 * v1).sum(-1)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "0e873f8d-1671-4450-8324-51c2ed2d93d1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[angle_l, angle_r]=(1.512980921295375, 1.628611732294418)\n"
     ]
    }
   ],
   "source": [
    "theta = np.arccos(cos_theta)\n",
    "\n",
    "# (1.500026590132683, 1.6415660634571103)\n",
    "angle_l = np.arccos(0.1 / np.sqrt(2))\n",
    "angle_r = np.arccos(-0.1 / np.sqrt(2))\n",
    "\n",
    "# (1.5129812741875936, 1.6286113794021995)\n",
    "angle_l = theta\n",
    "angle_r = theta + 2 * (np.pi / 2 - theta)\n",
    "print(f'[angle_l, angle_r]=({angle_l}, {angle_r})')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "20d2e5d8-4cf1-4fca-bc79-db96ed83cfbb",
   "metadata": {},
   "outputs": [],
   "source": [
    "def F_pr(theta):\n",
    "    return torch.sqrt(2 + torch.cos(theta).square())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "637c29c4-3ab3-4d66-8da2-6f07329626a1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor(0.1636, dtype=torch.float64)\n"
     ]
    }
   ],
   "source": [
    "num_dis = 10000\n",
    "ts = torch.linspace(angle_l, angle_r, num_dis)\n",
    "h = (angle_r - angle_l) / num_dis\n",
    "Fs = F_pr(ts)\n",
    "arc_length = Fs.sum() * h\n",
    "\n",
    "print(arc_length)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38e8b9cc-0215-4f35-aaa3-09bd2d8d8e20",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
